package model
{
	import mx.collections.ArrayCollection;
	
	[Bindable]
	public class Model
	{
		public function Model() {
			if (Model._instance != null) return;
			_navigationPath = new ArrayCollection();
			_pageIndex = new ArrayCollection();
		}
		
		public static function get instance(): Model {
			if (_instance == null) {
				_instance = new Model();
			}
			return _instance;
		}
		
		public function get newPage(): Page {
			return _newPage;
		}
		
		public function set newPage(p:Page): void {
			trace("set newPage to " + p);
			_newPage = p;
		}
		
		public function get currentPage(): Page {
			return _currentPage;
		}
		
		public function set currentPage(p:Page): void {
			if (p==null || _currentPage==null || p.pageId != _currentPage.pageId) {
				trace("set currentPage to " + p);
				setPreviousPage(_currentPage);
				_currentPage = p;
			}
		}
		
		public function get previousPage(): Page {
			return _previousPage;
		}
		
		public function set previousPage(p:Page): void {
			setPreviousPage(p);
		}
		
		public function get navigationPath(): ArrayCollection {
			return _navigationPath;
		}
		
		public function set navigationPath(value: ArrayCollection): void {
			_navigationPath = value;
		}
		
		public function get pageIndex(): ArrayCollection {
			return _pageIndex;
		}
		
		public function set pageIndex(value: ArrayCollection): void {
			_pageIndex = value;
		}
		
		private function setPreviousPage(p:Page): void {
			trace("set previousPage to " + p);
			_previousPage = p;
			if (_previousPage != null) {
				_navigationPath.addItem(_previousPage);
			}
		}
		
		public function get html(): String {
			return _html;
		}
		
		public function set html(value: String) {
			_html = value;
		}

		private static var _instance: Model = null;
		
		private var _newPage:Page = null;
		private var _currentPage:Page = null;
		private var _previousPage:Page = null;
		private var _navigationPath: ArrayCollection;
		private var _html:String = "";	
		private var _pageIndex:ArrayCollection;
	}
}